package com.daiyang.mybatisdome.mapper;

import com.daiyang.mybatisdome.model.UserInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.context.annotation.Primary;

import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select* from user_info")
//    @Results(id="11",value = {@Result(column = "delete_flag",property = "deleteflag"),
//            @Result(column = "create_time",property = "createtime"),
//            @Result(column = "update_time",property = "updatetime")})
    public List<UserInfo> queryAllUser();
//    @ResultMap(value = "11")
    @Select("select* from user_info")
    public List<UserInfo> queryAllUser2();
    @Select("select username, `password`, age, gender, phone from user_info where id=#{id1} or id=#{id2}")
    public List<UserInfo> queryAllUserById(String id1,String id2);
    @Select("select username, `password`, age, gender, phone from user_info where id=#{id} and username=#{name}")
    public List<UserInfo> queryAllUserById_and_Name(@Param("id") String i,@Param("name") String n);

//    @Insert("insert into user_info(username, `password`, age, gender, phone) values ("","",22,1,19939942163)"))
    @Insert("insert into user_info (username, `password`, age, gender, phone) values(#{username},#{password},#{age},#{gender},#{phone})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    public Integer insertUser(String username ,String password,Integer age,String gender,String phone);
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into user_info (username, `password`, age, gender, phone) values(#{UI.username},#{UI.password},#{UI.age},#{UI.gender},#{UI.phone})")
    public Integer insertUser2(@Param("UI") UserInfo userInfo);
    @Delete("delete from user_info where id=#{id}")
    public Integer deleteUserById(@Param("id") Integer id);
    @Update("update user_info set username=#{username} where id=#{id}")
    public Integer updateUserById(UserInfo userInfo );
//    @Select("select username, `password`, age, gender, phone from user_info where  id= #{id} ")
//    UserInfo queryById(Integer id);
//    @Select("select username, `password`, age, gender, phone,delete_flag from user_info where  id= ${id} ")
//    UserInfo queryById2(Integer id);
@Select("select username, `password`, age, gender, phone from user_info where  username= #{username} ")
UserInfo queryById(String username);
    @Select("select username, `password`, age, gender, phone,delete_flag  where  username='${username}'")
    UserInfo queryById2(String username);

    @Select("select username, `password`, age, gender, phone,delete_flag from user_info order by id ${sort}")
    List<UserInfo> queryAllUserBySort(String sort);
    @Select("select username, `password`, age, gender, phone,delete_flag from user_info order by id #{sort}")
    List<UserInfo> queryAllUserBySort2(String sort);
    @Select("select id, username, age, gender, phone, delete_flag, create_time, update_time " +
            "from user_info where username like '%${key}%' ")
    List<UserInfo> queryAllUserByLike(String key);
}
